| Total Complexity | 6 |
| Total Lines | 27 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | class Queue1 { |
||
| 27 | class Queue2 { |
||
| 28 | // put your code here to address problems |
||
| 29 | constructor(stack1, stack2) { |
||
| 30 | this.stack1 = stack1; |
||
| 31 | this.stack2 = stack2; |
||
| 32 | } |
||
| 33 | enqueue(record) { |
||
| 34 | this.stack1.push(record); |
||
| 35 | } |
||
| 36 | dequeue() { |
||
| 37 | let result; |
||
| 38 | // - Pop out all elements from Stack1, push to Stack2 |
||
| 39 | while (this.stack1.top()) { |
||
| 40 | this.stack2.push(this.stack1.pop()); |
||
| 41 | } |
||
| 42 | // - Pop from Stack2 |
||
| 43 | result = this.stack2.pop(); |
||
| 44 | // - Pop out all remaining elements from Stack2, push back to Stack1 |
||
| 45 | while (this.stack2.top()) { |
||
| 46 | this.stack1.push(this.stack2.pop()); |
||
| 47 | } |
||
| 48 | return result; |
||
| 49 | } |
||
| 50 | peek() { |
||
| 51 | return this.stack1.data; |
||
| 52 | } |
||
| 53 | } |
||
| 54 | |||
| 59 |